package com.linln.wtp.controller.rate;

import com.linln.common.enums.RateEnum;
import com.linln.common.utils.DateUtil;
import com.linln.common.utils.SessionUtil;
import com.linln.common.vo.JsonResult;
import com.linln.component.wtpshiro.annotation.UserLoginToken;
import com.linln.modules.rate.domain.Rate;
import com.linln.modules.rate.service.RateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.wtp.controller.rate
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.wtp.controller.rate
 * @Description: TODO
 * @date Date : 2021年01月06日 10:07
 */
@RestController
@RequestMapping("rate")
@Slf4j
public class RateController {

    @Autowired
    private RateService rateService;

    @UserLoginToken
    @PostMapping("/addRate")
    public JsonResult addRateController(@RequestParam("shopId") String shopId, @RequestParam("score") Integer score
            , @RequestParam("content") String content, @RequestParam("anonymous") Boolean anonymous, @RequestParam("ticketId") String ticketId) {
        Rate rate = new Rate();
        rate.setShopId(shopId);
        rate.setRateDate(DateUtil.formatDate(new Date()));
        rate.setRateScore(score);
        rate.setRateContent(content);
        rate.setIsAnonymous(anonymous);
        rate.setTicketId(ticketId);
        rate.setUserId(SessionUtil.getUserId());
        rate.setStatus(RateEnum.WAITEXAMINE.getCode());
        return rateService.addRate(rate) ? JsonResult.ok() : JsonResult.error();
    }



    @GetMapping
    public Map<String,Object> getAllRate(@RequestParam(required = false, defaultValue = "0", value = "pageNum") Integer pageNum, @RequestParam(required = false, defaultValue = "10") Integer limit,@RequestParam("shopId")String shopId){
        return rateService.getRateListByShopId(pageNum,limit,shopId);
    }

}
